//
//  NetHandle.m
//  网易新闻
//
//  Created by 朱彦名 on 16/4/9.
//  Copyright © 2016年 朱彦名. All rights reserved.
//

#import "NetHandle.h"

@implementation NetHandle

+ (void)handleDataWithUrl: (NSString *)url completion: (void (^)(id result, NSURLResponse *  response, NSError *  error))block{

    NSURL *url1 = [NSURL URLWithString:url];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionTask *task = [session dataTaskWithURL:url1 completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        if (data) {
            id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                block(result, response, error);
            });
        }
    }];
    [task resume];

}
@end
